package com.imay.live.view;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Shader;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by lzx 16/7/12.
 */
public class WhiteLineView extends View {
    Paint p;

    public WhiteLineView(Context context) {
        super(context);
    }

    public WhiteLineView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public WhiteLineView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(21)
    public WhiteLineView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (p == null) {
            p = new Paint();
        }
        Rect wrect = new Rect(0, 0, canvas.getWidth(), getMeasuredHeight());
        LinearGradient lgw = new LinearGradient((wrect.width() >> 1), 0,
                (wrect.width() >> 1), (float) (wrect.height() * 0.9), Color.argb(255, 142, 142, 142), Color.argb(0, 255, 255, 255),
                Shader.TileMode.CLAMP);
        p.setShader(lgw);
        canvas.drawRect(wrect, p);
    }
}
